package com.itheima.test02;

import java.util.HashMap;
import java.util.Scanner;
import java.util.Set;
import java.util.TreeMap;

public class Test05 {
    public static void main(String[] args) {
        TreeMap<Character, Integer> hm = new TreeMap<>();
        Scanner sc = new Scanner(System.in);
        System.out.println("请输入字符串:");
        String s = sc.nextLine();
        for (int i = 0; i < s.length(); i++) {
            //s.charAt(i)
            char key = s.charAt(i);
            Integer value = hm.get(key);
            if (!hm.containsKey(key)) {
                hm.put(key, 1);
            } else {
                value++;
                hm.put(key, value);
            }
        }

        Set<Character> keys = hm.keySet();
        StringBuilder sb = new StringBuilder();
        for (Character key : keys) {
            sb.append(key).append("(").append(hm.get(key)).append(")");
        }
        System.out.println(sb);

    }
}
